package cn._2dland.comment.locator
{
	import cn._2dland.comment.CommentMC;
	
	import flash.geom.Rectangle;

	public class FixedBottomLocator extends CommentLocator
	{
		public function FixedBottomLocator() {
			super();
		}

		override public function locate(cmnt:CommentMC, rect:Rectangle):void {
			// 固定弹幕速度为0
			cmnt.xSpeed = 0;
			cmnt.ySpeed = 0;

			// 横向居中显示
			cmnt.logicX = (rect.width - cmnt.width) / 2;
			cmnt.logicY = 0 - cmnt.height;

			// 计算纵坐标
			if(_comments.length == 0) {
				_comments.push(cmnt);
			}
			else{
				for(var i:int=0; i<_comments.length; i++) {
					var c:CommentMC = _comments[i] as CommentMC;
					if(c == null) continue;

					if(i==0 && 0- c.logicY - c.height >= cmnt.height) {
						_comments.splice(0, 0, cmnt);
						break;
					}
					else if(i == (_comments.length - 1)){
						cmnt.logicY = c.logicY - cmnt.height;
						_comments.push(cmnt);
						break;
					}
					else{
						var c2:CommentMC = _comments[i+1] as CommentMC;
						if(c.logicY - c2.logicY - c2.height >= cmnt.height){
							cmnt.logicY = c.logicY - cmnt.height;
							_comments.splice(i + 1, 0, cmnt);
							break;
						}
					}
				}
			}
			
			cmnt.x = cmnt.logicX;
			cmnt.y = cmnt.logicY % rect.height;
		}
	}
}